package com.example.api.controller;

import com.example.api.module.user.vo.UserVO;
import com.example.api.service.IUserFeignService;
import com.example.api.validator.group.Insert;
import com.example.common.api.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.CompletableFuture;

@RestController
@RequestMapping("/api/user")
@Api(tags = "用户管理")
@Slf4j
@Validated
public class UserFeignController {

    @Resource
    private IUserFeignService userFeignService;

    @ApiOperation("登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "账号", dataType = "string", paramType = "query", example = "zhangjw"),
            @ApiImplicitParam(name = "password", value = "密码", dataType = "string", paramType = "query", example = "123456")
    })
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public ResultUtil login(@NotBlank(message = "账号不能为空") @RequestParam String mobile,
                            @NotBlank(message = "密码不能为空") @RequestParam String password){
        return userFeignService.login(mobile, password);
    }

    @ApiOperation("创建用户")
    @RequestMapping(value = "/create_user", method = RequestMethod.POST)
    @ResponseBody
    public ResultUtil createUser(@RequestBody @Validated(Insert.class) UserVO user){
        return userFeignService.createUser(user);
    }

    @ApiOperation("获取用户")
    @RequestMapping(value = "/get_user", method = RequestMethod.GET)
    @ResponseBody
    public ResultUtil getUser(@RequestParam("mobile") String mobile,
                                 @RequestParam("password") String password){
        return userFeignService.getUser(mobile, password);
    }
}
